home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4582 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  46 lines

  1. Path: howland.reston.ans.net!usc!usc!not-for-mail
  2. From: wawda@alcor.usc.edu (Abu Wawda)
  3. Newsgroups: comp.lang.c++
  4. Subject: Why Do I Use An Ampersand in Member Class Parameters?
  5. Date: 30 Jan 1996 19:33:54 -0800
  6. Organization: University of Southern California, Los Angeles, CA
  7. Sender: wawda@alcor.usc.edu
  8. Distribution: world
  9. Message-ID: <4emnv2$n5o@alcor.usc.edu>
  10. NNTP-Posting-Host: alcor.usc.edu
  11.  
  12. class Simple
  13. {
  14. public:
  15.   Simple();
  16.   int operator += (const Simple &);
  17. private:
  18.   int data;
  19. };
  20.  
  21. I have seen many examples of this but I what I don't understand is why
  22. there is an amersand after Simple? I would wind up implementating the
  23. function as something like the following:
  24.  
  25. int Simple::operator += (const Simple ¶meter)
  26. {
  27.   data += parameter.data;
  28. }
  29.  
  30. I mean, I would understand if I parameter were a pointer to a Simple
  31. class, but that is not the case, since I am not doing:
  32.  
  33. int Simple::operator += (const Simple ¶meter)
  34. {
  35.   data += parameter->data;
  36. }
  37.  
  38. Then why is there an amersand? I would appreciate any
  39. suggestions. Thank you!
  40.  
  41.  
  42. -Abu Wawda
  43.  wawda@scf.usc.edu
  44.  
  45.  
  46.